package com.zbest.zpay.acctrans.component;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.zbest.zpay.acctrans.common.exception.AccTransRuntimeException;
import com.zbest.zpay.acctrans.dal.mapper.InnerInfMapper;
import com.zbest.zpay.acctrans.dal.model.InnerInf;
import com.zbest.zpay.acctrans.dal.model.TransJnl;
import com.zbest.zpay.acctrans.enums.ActAttrFlag;
import com.zbest.zpay.acctrans.enums.biz.AcctransBizCode;

public class QueryInnerAccountComponent {
    private static final Logger logger = LoggerFactory.getLogger(QueryInnerAccountComponent.class);

    @Autowired
    private InnerInfMapper innerInfMapper;

    public InnerInf queryDrInner(TransJnl transJnl) {
        InnerInf innerInf = null;
        String actAttr = transJnl.getDrActAttr();
        if (StringUtils.equals(actAttr,
                ActAttrFlag.ACCOUNT_ATTR_INN.getCode())) {
            String inActNo = transJnl.getDrActNo();
            innerInf = innerInfMapper.qryInnerInf(inActNo);
            if (innerInf == null) {
                throw new AccTransRuntimeException(
                        AcctransBizCode.ACT_INNER_ACCOUNT_NOT_EXIST, "内部账户信息不存在");
            }
        }
        return innerInf;
    }

    public InnerInf queryCrInner(TransJnl transJnl) {
        InnerInf innerInf = null;
        String actAttr = transJnl.getCrActAttr();
        if (StringUtils.equals(actAttr,
                ActAttrFlag.ACCOUNT_ATTR_INN.getCode())) {
            String inActNo = transJnl.getCrActNo();
            innerInf = innerInfMapper.qryInnerInf(inActNo);
            if (innerInf == null) {
                throw new AccTransRuntimeException(
                        AcctransBizCode.ACT_INNER_ACCOUNT_NOT_EXIST, "内部账户信息不存在");
            }
        }
        return innerInf;
    }

}
